<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<div class="panel">
    <div id="classes-heading" class="panel-heading bg-gray-light">
        <h3 class="panel-title">指标描述<span id="title-duty-name-targetDesc" class="text-muted"> | </span></h3>
    </div>

    <div class="panel-body">
        <form th:id="'form_targetDesc_input'+${targetDesc?.id}" class="form-horizontal" autocomplete="off">
            <input type="hidden" name="keyId" th:value="${targetDesc?.id}">
            <input type="hidden" name="flowDutyId">
            <input type="hidden" name="flowDutyName">
            <input type="hidden" name="parentId" th:value="${target!=null ? target?.id : targetDesc?.target?.id}">

            <div class="form-group">
                <label class="col-md-2 control-label">指标定义<i class="fa fa-asterisk txt-color-red"></i></label>
                <div class="col-md-8">
                    <select id="targetDescDictId" name="targetDescDictId" class="form-control">
                        <option value="">请选择</option>
                        <option th:each="dict : ${targetDescDictList}" th:id="${dict.id}" th:value="${dict.id}" th:text="${dict.name}" th:selected="${dict == targetDesc?.targetDescDict}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-2 control-label">描述内容<i class="fa fa-asterisk txt-color-red"></i></label>
                <div class="col-md-8">
                    <textarea name="content" id="content" th:text="${targetDesc?.content}" rows="4" class="form-control" placeholder="描述内容"></textarea>
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-2 control-label">描述解释</label>
                <div class="col-md-8">
                    <textarea name="explanation" id="explanation" th:text="${targetDesc?.explanation}" rows="4" class="form-control" placeholder="描述解释"></textarea>
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-2 control-label">是否存在数据元<i class="fa fa-asterisk txt-color-red"></i></label>
                <div class="col-md-8">
                    <div class="radio">
                        <input type="radio" name="ifYuan" id="ifYuan0" value="否" class="magic-radio" th:checked="${targetDesc==null || targetDesc?.ifYuan=='否'}" >
                        <label for="ifYuan0">否</label>
                        <input type="radio" name="ifYuan" id="ifYuan1" value="是" class="magic-radio" th:checked="${targetDesc?.ifYuan == '是'}" >
                        <label for="ifYuan1">是</label>
                    </div>
                </div>
            </div>

            <div id="yuanDiv" class="form-group" th:hidden="${targetDesc==null || targetDesc?.ifYuan == '否'}" >
                <label class="col-md-2 control-label">指标数据元<i class="fa fa-asterisk txt-color-red"></i></label>
                <div class="col-md-8">
                    <input type="text" name="yuan" id="yuan" th:value="${targetDesc?.yuan}" class="form-control" placeholder="指标数据元">
                </div>
            </div>

        </form>
    </div>
</div>

<script th:inline="javascript">
    var editType_targetDesc = [[${editType}]];
    var keyId_targetDesc = [[${targetDesc?.id}]];
    var flowData_targetDesc = {
        keyId : keyId_targetDesc ? keyId_targetDesc : "create",
        formId : "form_targetDesc_input"+[[${targetDesc?.id}]],
        path : "com.hanqian.kepler.core.entity.primary.core.TargetDesc",
        titleId : "title-duty-name-targetDesc"
    };
    var $form_targetDesc = $("#"+flowData_targetDesc.formId);

    $(function(){
        __flow_duty_handle(flowData_targetDesc);
        __flow_button_input_handle(flowData_targetDesc, fn_targetDesc_save, fn_targetDesc_commit);
        fn_targetDesc_input_validate();

        __select2(flowData_targetDesc.formId + " #targetDescDictId");

        __summernote($form_targetDesc.find("#content"));

        if(editType_targetDesc === "update"){
            $("#targetDescDictId").attr("disabled", true);
        }

    });

    //选择“计算公式”后自动是否存在数据元改为“是”
    $form_targetDesc.on("change", "select[name='targetDescDictId']", function(){
        var val = $("select[name='targetDescDictId'] option:selected").text();
        if(val === "计算公式"){
            $(":radio[name='ifYuan'][id='ifYuan1']").trigger("click");
        }
    });

    //显示隐藏指标数据元
    $form_targetDesc.on("click", ":radio[name='ifYuan']", function(){
        var val = $(this).val();
        if(val === "是"){
            $form_targetDesc.find("#yuanDiv").show();
        }else{
            $form_targetDesc.find("#yuanDiv").hide();
        }
    });

    //表单验证
    function fn_targetDesc_input_validate(){
        __init_validate(flowData_targetDesc.formId, {
            rules : {
                targetDescDictId : {required : true},
                content : {required : true},
                explanation : {required : false},
                ifYuan : {required : true}
            }
        });
    }

    //保存方法
    function fn_targetDesc_save(){
        var msg = "确认保存吗";
        var url = ctx + "targetDesc/save";
        if(editType_targetDesc === "update"){
            msg = "本次执行更新将会创造出新版本，确认更新吗？";
            url = ctx + "targetDesc/save_v";
        }
        __confirm_dialog("", msg, function(){
            __form_save(flowData_targetDesc.formId, url, function(data){
                if(data && data.state === 1){
                    __flow_close_layx(flowData_targetDesc);
                }
            })
        })
    }

    //提交方法
    function fn_targetDesc_commit(){
        if(!$("#" + flowData_targetDesc.formId).valid()){
            return false;
        }
        __confirm_dialog("", "确认提交吗？", function(){
            __form_save(flowData_targetDesc.formId, ctx + "targetDesc/commit", function(data){
                if(data && data.state === 1){
                    __flow_close_layx(flowData_targetDesc);
                }
            })
        })
    }

</script>

</html>